{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def add_layer(inputs, in_size, out_size, activation_function=None):\n",
    "    \n",
    "    Weights = tf.Variable(tf.random_normal((in_size, out_size)))\n",
    "    biases = tf.Variable(tf.zeros((out_size)) + 0.1)\n",
    "    Wx_plus_b = tf.matmul(inputs, Weights) + biases\n",
    "    \n",
    "    if activation_function is None:\n",
    "        outputs = Wx_plus_b\n",
    "    else:\n",
    "        outputs = activation_function(Wx_plus_b)\n",
    "        \n",
    "    return outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.21308522\n",
      "0.010175895\n",
      "0.005326518\n",
      "0.00441782\n",
      "0.021356253\n",
      "0.007850157\n",
      "0.014110745\n",
      "0.0117727555\n",
      "0.010609681\n",
      "0.010242629\n",
      "0.00948543\n",
      "0.009144818\n",
      "0.008596602\n",
      "0.007980052\n",
      "0.00743611\n",
      "0.0069166557\n",
      "0.0066430187\n",
      "0.00636262\n",
      "0.006403857\n",
      "0.0064160754\n"
     ]
    }
   ],
   "source": [
    "x_data = np.linspace(-1, 1, 300)[:,np.newaxis]\n",
    "noise = np.random.normal(0, 0.05, x_data.shape)\n",
    "y_data = np.square(x_data) - 0.5 + noise\n",
    "\n",
    "xs = tf.placeholder(tf.float32, (None, 1))\n",
    "ys = tf.placeholder(tf.float32, (None, 1))\n",
    "l1 = add_layer(xs, 1, 10, tf.nn.relu)\n",
    "prediction = add_layer(l1, 10, 1, None)\n",
    "loss = tf.reduce_mean(tf.square(ys - prediction))\n",
    "train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)\n",
    "\n",
    "init = tf.initialize_all_variables()\n",
    "sess = tf.Session()\n",
    "sess.run(init)\n",
    "\n",
    "for i in range(1000):\n",
    "    sess.run(train_step, feed_dict={xs:x_data, ys:y_data})\n",
    "    if i % 50 == 0:\n",
    "        print(sess.run(loss, feed_dict={xs:x_data, ys:y_data}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
